<?php
class Search extends database{
    
    private $var_Result = '';
    
    public function getSearchResult(){
        return $this->var_Result;
    }

    public function SearchData($sql,$key,$value){
        
        $vRes = 'var search_result = [';
        
        $this->setSql($sql);
        $this->query();
        
        $data = $this->fetchArray();
        
        $count = 1;
        foreach ($data as $k=>$v) {
            $vals = '{'.$key.':"'.$v[$key].'", '.$value.':"'.$v[$value].'"'.'}';
            if(count($data) != 0 && $count < count($data)){
                $vRes .= $vals.',';            
            } elseif(count($data) != 0 && $count = count($data)) {
                $vRes .= $vals;           
            } 
            
            $count ++;
            
        }
        
        $vRes .= '];';
        
        $this->var_Result = $vRes;   
        
    }
    
    
}
?>